package com.fanbai.score.user.http;

import android.content.Context;

import com.fanbai.score.common.Utils.JsonUtils;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.common.http.HttpUtils;
import com.fanbai.score.common.http.WebCodes;
import com.fanbai.score.user.bean.DuiHuanGRB_Bean;
import com.fanbai.score.user.bean.RedInfo_Bean;
import com.fanbai.score.user.bean.Scorestat_Bean;
import com.tencent.bugly.crashreport.CrashReport;

import java.util.HashMap;
import java.util.List;

/**
 * Created by acer on 2017/6/3.
 */

public class UserScorea_RequestNet_Utils {

    /**
     * 获取积分可兑换信息
     * @param ctx
     * @param callBack
     */
    public static void getScorestat(final Context ctx, final CallBack<Scorestat_Bean> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getscorestat");
        String url = WebCodes.HTTP_URL_USER_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    Scorestat_Bean bean = JsonUtils.toBean(body, Scorestat_Bean.class);
                    if (callBack != null)
                        callBack.onSuccess(ret, msg, bean);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 获取积分统计信息
     * @param ctx
     * @param callBack
     */
    public static void getScoreTotalInfo(final Context ctx, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getscoretotalinfo");
        String url = WebCodes.HTTP_URL_USER_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    if (callBack != null)
                        callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 积分兑换贵人币
     * @param ctx
     * @param callBack
     */
    public static void exchargecoin(final Context ctx, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "exchargecoin");
        String url = WebCodes.HTTP_URL_USER_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    if (callBack != null)
                        callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 获取红包信息
     * @param ctx
     * @param callBack
     */
    public static void getRedbagInfos(final Context ctx, final CallBack<List<RedInfo_Bean>> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getredbaginfos");
        String url = WebCodes.HTTP_URL_USER_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    List<RedInfo_Bean> beans = JsonUtils.toArr(body, RedInfo_Bean[].class);
                    if (callBack != null)
                        callBack.onSuccess(ret, msg, beans);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     *兑换红包
     * @param ctx
     * @param rbid 红包ID
     * @param callBack
     */
    public static void exchargeRedbag(final Context ctx, String rbid, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "exchargeredbag");
        params.put("rbid", rbid);
        String url = WebCodes.HTTP_URL_USER_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    if (callBack != null)
                        callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     *活动中领取积分接口
     * @param ctx
     * @param callBack
     */
    public static void pickupEveryScore(final Context ctx, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "pickupeveryscore");
        String url = WebCodes.HTTP_URL_USER_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    if (callBack != null)
                        callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }
    /**
     *活动中领取贵人币
     * @param ctx
     * @param callBack
     */
    public static void pickupEveryCoin(final Context ctx, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "pickupeverycoin");
        String url = WebCodes.HTTP_URL_USER_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    if (callBack != null)
                        callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }
    /**
     *积分兑换预计算
     * @param ctx
     * @param callBack
     */
    public static void getscoreexchargestat(final Context ctx, final CallBack<DuiHuanGRB_Bean> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getscoreexchargestat");
        String url = WebCodes.HTTP_URL_USER_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    DuiHuanGRB_Bean bean = JsonUtils.toBean(body, DuiHuanGRB_Bean.class);
                    if (callBack != null)
                        callBack.onSuccess(ret, msg, bean);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

}
